#!/bin/sh
#copyright @tangxuning


list=`sudo netstat  -nltvp  | grep node |awk '{print $4,$7}'`
i=0
for node in $list
do
	let i=$i+1
	if [ $i == 1 ]
	then
		echo -n "端口:$node  | "
	fi
	if [ $i == 2 ]
	then
#		echo "$node"
		pid=`echo -n $node |awk -F/ '{printf $1}'`
		cwd=`sudo lsof  -p $pid | grep cwd | awk '{printf $9}'`
		echo -n -e "\033[31m目录：$cwd  \033[0m | "
		version=`sudo su -c "cd $cwd ; git symbolic-ref  -q HEAD" root -s /bin/bash`
		date=`sudo su -c "cd $cwd ;git log  -n 1 | grep Date"  root -s /bin/bash`
		echo -e "分支：$version  | \033[31m $date\033[0m"		
		echo ""
		i=0
	fi
	
	
done


#cmd1=`sudo netstat  -nltvp  | grep node |awk  '{print $4}' |awk -F: '{print $2}'`
#cmd2=`sudo netstat  -nltvp  | grep node |awk  '{print $7}' |awk -F/ '{print $1}'`

#echo "${cmd1}"
#echo "${cmd2}"

#for port ,pid in "${cmd1}" "${cmd2}"
#do
#	echo -n "端口：$port "
#	echo  "PID：$pid "
#done

#for ((i=0;i<=${#cmd1[@]};i++)); do
#      echo  "端口$cmd1[i]" "PID$cmd2[i]"
#done


